#include <stdio.h>
#include <string.h>


int stoi( const char *n )
{
	int len = strlen( n );
	int base = 1;
	int ret = 0;
	char c;

	while ( len ) {
		c = n[len - 1];
		ret += base * ( c - '0' );
	
		base *= 10;

		--len;
	}

	printf( "%d\n", ret );

	return ret;
}


unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
{
	unsigned long result = 0,value;

	if (!base) {
		base = 10;
		if (*cp == '0') {
			base = 8;
			cp++;
			if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
				cp++;
				base = 16;
			}
		}
	} else if (base == 16) {
		if (cp[0] == '0' && toupper(cp[1]) == 'X')
			cp += 2;
	}
	while (isxdigit(*cp) &&
			(value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
		result = result*base + value;
		cp++;
	}
	if (endp)
		*endp = (char *)cp;
	return result;
}

int main( void )
{
	char *a = "123";
	char *cp = NULL;

	unsigned long  b = 0;

//	b = stoi( a,&cp, 0 );
	b = simple_strtoul( a,&cp, 0 );

	printf( "%d\n", b );
	
	return 1; 
}
